package com.sumainfor.pc.market.controller.tenant;

import com.sumainfor.common.util.FieldCheckUtil;
import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.market.feign.GmioFeign.GmioFeign;
import com.sumainfor.pc.market.service.tenant.impl.TenantOwnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能描述:
 *
 * @Auther: zhlu
 * @Date: 2019/3/12 19:22
 * @Description:
 */
@RestController
@RequestMapping("/tenant/key/owner")
public class TenantOwnerController {

    @Autowired
    TenantOwnerService TenantOwnerService;

    @Autowired
    GmioFeign GmioFeign;

    /**
     * 功能描述: 
     * 根据微信端的用户手机号判断当前租客是否是业主
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/12 19:25
     */
    @GetMapping("/getSigningWechatOwner")
    public JsonResult getSigningWechatOwner(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"OwPhone"})){
            result.putFailed("OwPhone不能为空！");
            return  result;
        }
        params.put("OwState",5);
        params.put("ProState",7);
        Map<String,Object> getSigningWechatOwner=TenantOwnerService.getSigningWechatOwner(params);
        return result.put(getSigningWechatOwner);
    }

    /**
     * 功能描述:
     * 根据openid获取当前业主托管房源总数
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/12 19:25
     */
    @GetMapping("/getWechatOwnerCount")
    public JsonResult getWechatOwnerCount(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        params.put("OwState",5);
        params.put("ProState",7);
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"OwPhone"})){
            result.putFailed("OwPhone不能为空！");
            return  result;
        }
        Integer getSigningWechatOwner=TenantOwnerService.getWechatOwnerCount(params);
        return result.put(getSigningWechatOwner);
    }

    /**
     * 功能描述: 
     * 根据业主openId获取业主房源情况
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/13 19:41
     */
    @GetMapping("/getWechatOwnerHousing")
    public JsonResult getWechatOwnerHousing(@RequestParam Map<String,Object>params,Pager pager){
        JsonResult result=new JsonResult();
        params.put("delfg",0);
        params.put("OwState",5);
        params.put("ProState",7);
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"OwPhone"})){
            result.putFailed("OwPhone不能为空！");
            return  result;
        }

        Integer cout=TenantOwnerService.getWechatOwnerHousingCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>>getWechatOwnerHousing=TenantOwnerService.getWechatOwnerHousing(params);
        result=pageUtils.getJsonResult(getWechatOwnerHousing, params, cout);
        return result;
    }

    /**
     * 功能描述: 
     * 根据业主房源主编号获取房源信息
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/3/14 11:19
     */
    @GetMapping("/getWechatHousingMap")
    public JsonResult getWechatHousingMap(@RequestParam Map<String,Object>params)throws Exception{
        JsonResult result=new JsonResult();
        if(!FieldCheckUtil.isMapFieldNotNull(params,new String[]{"HouId"})){
            result.putFailed("HouId不能为空！");
            return  result;
        }
        params.put("delfg",0);
        result.put(TenantOwnerService.getWechatHousingMap(params));
        return result;
    }

    /**
     * 功能描述: 
     * 根据业主账单编号获取业主银行卡资料、业主账单资料
     * @Author zhlu
     * @Description //TODO
     * @Date 2019/4/1 19:53
     */
    @GetMapping("/getOwnerDealPayMap")
    public JsonResult getOwnerDealPayMap(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        JsonResult jsonresult=GmioFeign.getOwnerBillMap(params);
        if(jsonresult.isSuccess()==false){
            return jsonresult;
        }
        params.putAll((Map<String,Object>)jsonresult.getResult());
        Map<String,Object>getOwnerDealPayMap=TenantOwnerService.getOwnerDealPayMap(params);
        getOwnerDealPayMap.putAll((Map<String,Object>)jsonresult.getResult());
        result.put(getOwnerDealPayMap);
        return result;
    }

}


